/**
 * Created by hjy on 2017/8/27.
 *
 * 把图片转换成base64
 */
var fs = require('fs')

fs.readFile('1.jpg',function (err,origin_buffer) {
    console.log(Buffer.isBuffer(origin_buffer))// 是buffer对象

    fs.writeFile('1_buffer.jpg',origin_buffer,function (err) {
        if(err) console.log(err)
    })

    var base64Image = origin_buffer.toString('base64')
    console.log(base64Image)// base64

    var decodedImage = new Buffer(base64Image,'base64')
    console.log(Buffer.compare(origin_buffer,decodedImage))//origin_buffer跟decodedImage是一样的

    fs.writeFile('1_decoded.png',decodedImage,function (err) {
        if(err) console.log(err)
    })
})

